package slingge.cooleuropeweather;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;

import java.util.ArrayList;
import java.util.List;

import slingge.cooleuropeweather.adapter.ListViewAdapter;
import slingge.cooleuropeweather.view.MyListView;

public class Message extends AppCompatActivity {

    private String LocationName,PhoneNumber;
    public double latitude,longitude;
    private MyListView list4;
    public int CO,SO2,O3,NO2,PM10,PM25;
    public String Qlty,AQI,Temper,Weather;
    private String str;
    private Uri uri;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_message);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        list4 = (MyListView) findViewById(R.id.list4) ;
        Intent intent = this.getIntent();
        LocationName = intent.getStringExtra("location");
        latitude = intent.getDoubleExtra("latitude",0.0);
        longitude = intent.getDoubleExtra("longitude",0.0);
        Temper = intent.getStringExtra("Temper");
        Weather = intent.getStringExtra("Weather");
        AQI = intent.getStringExtra("AQI");
        Qlty = intent.getStringExtra("Qlty");
        CO = intent.getIntExtra("CO",0);
        SO2 = intent.getIntExtra("SO2",0);
        NO2 = intent.getIntExtra("NO",0);
        O3 = intent.getIntExtra("O3",0);
        PM10 = intent.getIntExtra("PM10",0);
        PM25 = intent.getIntExtra("PM2.5",0);
        PhoneNumber = intent.getStringExtra("PhoneNumber");
        uri = intent.getParcelableExtra("Uri");
        List<String> strList1 = new ArrayList<>();
        strList1.add("收件人："+PhoneNumber);
        strList1.add("地  址："+ LocationName+'\n'+'('+latitude+'，'+longitude+')');
        strList1.add("温  度："+Temper+"  天气状况："+Weather);
        strList1.add("AQI指数："+AQI+"  质量等级："+Qlty);
        strList1.add("PM2.5："+PM25+" ug/m³"+"    PM10："+PM10+" ug/m³");
        strList1.add("SO2:"+SO2+" ug/m³"+"   CO:"+CO+" ug/m³" );
        strList1.add("O3:"+O3+" ug/m³"+"   NO2："+NO2+" ug/m³");
        ListViewAdapter lifeAdapter1 = new ListViewAdapter(this, strList1);
        list4.setAdapter(lifeAdapter1);
        str = "大致位置："+ LocationName+"  当前温度："+Temper+"  天气状况："+Weather+"\n"+"AQI指数："+AQI+"  质量等级："+Qlty+
                "  PM2.5："+PM25+"mg/m3"+"  PM10："+PM10+"mg/m3"+"  SO2："+SO2+"mg/m3"+"  CO："+CO+"mg/m3"+
                "  O3："+O3+"mg/m3"+"  NO2："+NO2+"mg/m3";
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Uri smsToUri = Uri.parse("smsto:"+PhoneNumber);
                Intent i = new Intent( android.content.Intent.ACTION_SENDTO, smsToUri );
                i.putExtra("sms_body",str);
                i.putExtra(Intent.EXTRA_STREAM, uri);
                startActivity(i);
                Snackbar.make(view, "信息已成功添加！"+uri, Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }
}
